package com.yntx.usercenter.authentication.controller;

import com.yntx.usercenter.authentication.service.OtpService;
import com.yntx.usercenter.authentication.vo.OtpQrCodeVo;
import com.yntx.usercenter.authentication.vo.OtpVo;
import com.yntx.usercenter.common.web.ApiResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * otp控制器
 *
 * @author jielihaofeng
 * @date 2023-04-26 15:38
 */
@RestController
@RequestMapping("/otp")
@AllArgsConstructor
public class OtpController {

    private OtpService totpService;

    @GetMapping("/autoRefresh")
    public ApiResult<OtpVo> autoRefresh(String otpSecret) {
        return ApiResult.ofSuccess(totpService.getOtp(otpSecret));
    }

    @GetMapping("/getOtpQrCode")
    public ApiResult<OtpQrCodeVo> getOtpQrCode(String username, String otpSecret) {
        return ApiResult.ofSuccess(totpService.getOtpQrCode(username, otpSecret));
    }

}
